package com.carcenter.order.entity;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class NewAppointmentDto {
    @NotNull(message = "用户ID不能为空")
    private Integer userId;

    @NotNull(message = "门店ID不能为空")
    private Integer storeId;

    @NotNull(message = "开始时间不能为空")
    private LocalDateTime startTime;

    @NotNull(message = "结束时间不能为空")
    private LocalDateTime endTime;

    private String appointmentNotes;
    private List<AppointmentProduct> appointmentProducts = new ArrayList<>();
    private List<AppointmentService> appointmentServices = new ArrayList<>();

    // 至少有产品或服务
    @AssertTrue(message = "产品和服务不能同时为空")
    public boolean isValid() {
        return !appointmentProducts.isEmpty() || !appointmentServices.isEmpty();
    }

    // 开始时间必须早于结束时间
    @AssertTrue(message = "开始时间必须早于结束时间")
    public boolean isValidTimeRange() {
        return startTime != null && endTime != null && startTime.isBefore(endTime);
    }
}
